package com.scalesoft.artsync.frontend.controller;

import java.awt.Toolkit;

import javax.swing.SwingWorker;

import com.scalesoft.artsync.frontend.view.ProgressDialogView;

public class ProgressDialogController {

	public ProgressDialogView view;
	private Task task;
	private int value;
	private int minimum;
	private int maximum;
	private String message;

	class Task extends SwingWorker<Void, Void> {
		/*
		 * Main task. Executed in background thread.
		 */
		@Override
		public Void doInBackground() {
			while (true) {
				view.getProgressBar().setMinimum(minimum);
				view.getProgressBar().setMaximum(maximum);
				view.getProgressBar().setValue(value);
				view.getLabelMessage().setText(message);
				view.pack();
				try {
					Thread.sleep(200);
				} catch (InterruptedException ignore) {
				}
			}
		}

		/*
		 * Executed in event dispatching thread
		 */
		@Override
		public void done() {
			Toolkit.getDefaultToolkit().beep();
		}
	}

	public ProgressDialogController(ProgressDialogView view) {
		this.view = view;
		task = new Task();
		task.execute();

	}

	public void setMaximum(int value) {
		this.maximum = value;
	}

	public void setMinimum(int value) {
		this.minimum = value;
	}

	public void setValue(int value) {
		this.value = value;
	}

	public void setMessage(String message) {
		this.message = message;
	}

}
